package com.moco.launcher.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationSet;

import com.moco.launcher.R;
import com.moco.launcher.view.HoloCircularProgressBar;
import com.nineoldandroids.animation.Animator.AnimatorListener;
import com.nineoldandroids.animation.ObjectAnimator;
import com.nineoldandroids.animation.ValueAnimator;
import com.nineoldandroids.animation.ValueAnimator.AnimatorUpdateListener;

public class RithmFragment extends BaseFragment {

	private static final String TAG = "LyricsFragment";

	private AnimationSet animationSet = null;
	private ValueAnimator mValueAnimator = null;
	private ObjectAnimator mObjectAnimator = null;
	private HoloCircularProgressBar mHoloCircularProgressBar;
	private ObjectAnimator mProgressBarAnimator = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.rithm_layout, container,
				false);
		mHoloCircularProgressBar = (HoloCircularProgressBar) rootView
				.findViewById(R.id.holoCircularProgressBar);

		return rootView;
	}

	private void animate(final HoloCircularProgressBar progressBar,
			final AnimatorListener listener, final float progress,
			final int duration) {

		mProgressBarAnimator = ObjectAnimator.ofFloat(progressBar, "progress",
				progress);
		mProgressBarAnimator.setDuration(duration);

		mProgressBarAnimator.addListener(new AnimatorListener() {

			@Override
			public void onAnimationStart(
					com.nineoldandroids.animation.Animator animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationEnd(
					com.nineoldandroids.animation.Animator animation) {
				// TODO Auto-generated method stub
				progressBar.setProgress(progress);
			}

			@Override
			public void onAnimationCancel(
					com.nineoldandroids.animation.Animator animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationRepeat(
					com.nineoldandroids.animation.Animator animation) {
				// TODO Auto-generated method stub

			}
		});

		if (listener != null) {
			mProgressBarAnimator.addListener(listener);
		}
		mProgressBarAnimator.reverse();

		mProgressBarAnimator.addUpdateListener(new AnimatorUpdateListener() {
			@Override
			public void onAnimationUpdate(ValueAnimator animation) {
				// TODO Auto-generated method stub
				progressBar.setProgress((Float) animation.getAnimatedValue());
			}
		});
		progressBar.setMarkerProgress(progress);
		mProgressBarAnimator.start();
	}
}
